ANALYSIS ON GLOBAL WARMING AND THE PRODUCTION OF C02

IMPORT LIBRARIES

In [2]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly
import plotly.graph_objs as go
import plotly.tools as tls
import seaborn as sns
import time
import warnings
import cartopy.crs as ccrs
warnings.filterwarnings('ignore')
import os
import plotly.express as px
import scipy
import datetime
from datetime import datetime
import pickle
import matplotlib.dates as mdates
In [1]:
import xarray as xr

FUNCTIONS

In [29]:
def fetch_year(date):
    return date.split('-')[0]

def get_season (month):
    if month>=3 and month<=5:
        return 'spring'
    elif month>=6 and month<=8:
        return 'summer'
    elif month>=9 and month<=11:
        return 'autumn'
    else:
        return 'winter'

IMPORT DATASETS

The dataasets are available at following links: -https://www.kaggle.com/datasets/berkeleyearth/climate-change-earth-surface-temperature-data -https://github.com/owid/co2-data -The models are some of the CMIP6 models that we have seen during the lessons

In [27]:
#os.chdir('C:\\Users\\User\\Documents\\Magistrale_SSE\\lab_Geographic info systems\\_PROGETTOFINALE2')
#os.getcwd()
global_temp = pd.read_csv('GlobalTemperatures.csv')
global_temp_country=pd.read_csv('GlobalLandTemperaturesByCountry.csv')
co2=pd.read_csv('owid-co2-data.csv')
In [8]:
os.getcwd()
Out[8]:
'C:\\Users\\User\\Documents\\Magistrale_SSE\\lab_Geographic info systems\\_PROGETTOFINALE2'
In [3]:
modfile1='ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc'
modfile2='ts_Amon_MIROC6_historical_r1i1p1f1_gn_185001-201412.nc'
modfile3='ts_Amon_MRI-ESM2-0_historical_r1i1p1f1_gn_185001-201412.nc'

AT THE BEGININNING WE ANALYZE THE AVERAGE LAND TEMPERATURE IN THE COURSE OF THE YEARS, THEN WE ANALYZE THE PRODUCTION OF CO2

In [30]:
global_temp['years']=global_temp['dt'].apply(fetch_year)
In [10]:
global_temp=global_temp[global_temp['years']>='1850']
In [11]:
global_temp.groupby('years').agg({'LandAverageTemperature':'mean','LandAverageTemperatureUncertainty':'mean'})
Out[11]:
LandAverageTemperature LandAverageTemperatureUncertainty
years
1850 7.900667 0.876417
1851 8.178583 0.881917
1852 8.100167 0.918250
1853 8.041833 0.835000
1854 8.210500 0.825667
... ... ...
2011 9.516000 0.082000
2012 9.507333 0.083417
2013 9.606500 0.097667
2014 9.570667 0.090167
2015 9.831000 0.092167

166 rows × 2 columns

In [12]:
data=global_temp.groupby('years').agg({'LandAverageTemperature':'mean','LandAverageTemperatureUncertainty':'mean'}).reset_index()
#creiamo l'estremo superiore e l'estremo inferiore del nostro intervallo
data['Uncertainty top']=data['LandAverageTemperature']+data['LandAverageTemperatureUncertainty']
data['Uncertainty bottom']=data['LandAverageTemperature']-data['LandAverageTemperatureUncertainty']
In [13]:
fig=px.line(data,x='years',y=['LandAverageTemperature',
       'Uncertainty top', 'Uncertainty bottom'],title='Average Land Tmeperature in World')
fig.show()

Let's focus ourselves on the seasons

In [14]:
global_temp['dt']=pd.to_datetime(global_temp['dt'])
global_temp['month']=global_temp['dt'].dt.month
global_temp['season']=global_temp['month'].apply(get_season)
years=global_temp['years'].unique()
spring_temps=[]
summer_temps=[]
autumn_temps=[]
winter_temps=[]
In [15]:
for year in years:
    current_year=global_temp[global_temp['years']==year]
    spring_temps.append(current_year[current_year['season']=='spring']['LandAverageTemperature'].mean())
    summer_temps.append(current_year[current_year['season']=='summer']['LandAverageTemperature'].mean())
    autumn_temps.append(current_year[current_year['season']=='autumn']['LandAverageTemperature'].mean())
    winter_temps.append(current_year[current_year['season']=='winter']['LandAverageTemperature'].mean())
#Now let's make a dataframe on season
season=pd.DataFrame()
season['year']=years
season['spring_temp']=spring_temps
season['summer_temp']=summer_temps
season['autumn_temp']=autumn_temps
season['winter_temp']=winter_temps
In [16]:
fig=px.line(season,x='year',y=['spring_temp', 'summer_temp', 'autumn_temp', 'winter_temp'],title='Average temperature in Each season')
fig.show()

From the charts we can see, that there is global warming nowadays. The average temperature of Earth surface has the highest value in the last three centuries. The fastest temperature growth occurred in the last 30 years. This charts also have confidence intervals, which shows that measurement of temperature has become more accurate in the last few years.

FOCUS ON CO2 EMISSION

In [27]:
co2_inter=co2[['country','year','co2','gdp']]
co2_inter=co2_inter[co2_inter['country']!='World']
co2_agg=co2_inter.groupby('year').agg({'co2':'mean'}).reset_index()
In [28]:
fig=px.line(co2_agg,x='year',y='co2',title='Mean of co2 during the years')
fig.show()

from this graphic we can see that has been an augmentation of CO2 in the atmosphere from the 1950, let's do a test between the mean of co2 and the land average temperature

In [29]:
global_agg=global_temp.groupby('years').agg({'LandAverageTemperature':'mean'}).reset_index() #temperatura media per anno
global_agg=pd.DataFrame(global_agg)
co2_agg=co2_agg[co2_agg['year']<=2015]
co2_agg=co2_agg[co2_agg['year']>=1850]
from scipy import stats
scipy.stats.pearsonr(co2_agg['co2'], global_agg['LandAverageTemperature'])
Out[29]:
PearsonRResult(statistic=0.8751956131048915, pvalue=1.3540117283304936e-53)

We refuse the hypothesis that the variables are not correlated,so CO2 is correlated with the Land Average Temperature

Let's now see if gdp is correlated with the augmentation of CO2

In [30]:
co2_gdp=co2_inter.groupby('year').agg({'gdp':'sum'}).reset_index()
In [31]:
co2_agg=co2_agg[co2_agg['year']<=2015]
co2_agg=co2_agg[co2_agg['year']>=1850]
co2_gdp=co2_gdp[co2_gdp['year']<=2015]
co2_gdp=co2_gdp[co2_gdp['year']>=1850]

from scipy import stats
scipy.stats.pearsonr(co2_agg['co2'], co2_gdp['gdp'])
Out[31]:
PearsonRResult(statistic=0.9395288360896425, pvalue=3.152489761450195e-78)

In statistics correlation is not synonymous of causality, but from this analysis we can see that there are bonds beteween the global average land co2 and the gdp of a country

Let's make a comparison between model ensemble from CMIP6 (this models simulate the augmentation of CO2 in the course of the years) and the current situation of the Average Land Temperature

In [6]:
d1 = xr.open_dataset(modfile1)
d2 = xr.open_dataset(modfile2)
d3 = xr.open_dataset(modfile3)
In [7]:
d1
Out[7]:
<xarray.Dataset>
Dimensions:      (lat: 143, lon: 144, time: 1980, axis_nbounds: 2)
Coordinates:
  * lat          (lat) float32 -90.0 -88.73 -87.46 -86.2 ... 87.46 88.73 90.0
  * lon          (lon) float32 0.0 2.5 5.0 7.5 10.0 ... 350.0 352.5 355.0 357.5
  * time         (time) datetime64[ns] 1850-01-16T12:00:00 ... 2014-12-16T12:...
Dimensions without coordinates: axis_nbounds
Data variables:
    time_bounds  (time, axis_nbounds) datetime64[ns] 1850-01-01 ... 2015-01-01
    ts           (time, lat, lon) float32 ...
Attributes: (12/51)
    Conventions:            CF-1.7 CMIP-6.2
    creation_date:          2018-07-11T07:36:33Z
    tracking_id:            hdl:21.14100/3168f5b1-bf0a-4aec-931f-73c9d0034a45
    description:            CMIP6 historical
    title:                  IPSL-CM6A-LR model output prepared for CMIP6 / CM...
    activity_id:            CMIP
    ...                     ...
    name:                   /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLC...
    further_info_url:       https://furtherinfo.es-doc.org/CMIP6.IPSL.IPSL-CM...
    variant_label:          r1i1p1f1
    realization_index:      1
    history:                Sat Dec  1 12:17:27 2018: ncatted -O -a realizati...
    NCO:                    "4.6.0"
xarray.Dataset
    • lat: 143
    • lon: 144
    • time: 1980
    • axis_nbounds: 2
    • lat
      (lat)
      float32
      -90.0 -88.73 -87.46 ... 88.73 90.0
      axis :
      Y
      standard_name :
      latitude
      long_name :
      Latitude
      units :
      degrees_north
      array([-90.      , -88.73239 , -87.46479 , -86.19718 , -84.92958 , -83.66197 ,
             -82.39436 , -81.12676 , -79.85915 , -78.59155 , -77.323944, -76.056335,
             -74.788734, -73.521126, -72.253525, -70.985916, -69.71831 , -68.45071 ,
             -67.1831  , -65.91549 , -64.64789 , -63.380283, -62.112675, -60.84507 ,
             -59.577465, -58.30986 , -57.042255, -55.774647, -54.507042, -53.239437,
             -51.971832, -50.704224, -49.43662 , -48.169014, -46.90141 , -45.633804,
             -44.366196, -43.09859 , -41.830986, -40.56338 , -39.295776, -38.028168,
             -36.760563, -35.492958, -34.225353, -32.957745, -31.690142, -30.422535,
             -29.15493 , -27.887323, -26.619719, -25.352112, -24.084507, -22.816902,
             -21.549295, -20.28169 , -19.014084, -17.746479, -16.478872, -15.211267,
             -13.943662, -12.676056, -11.408451, -10.140845,  -8.87324 ,  -7.605634,
              -6.338028,  -5.070423,  -3.802817,  -2.535211,  -1.267606,   0.      ,
               1.267606,   2.535211,   3.802817,   5.070423,   6.338028,   7.605634,
               8.87324 ,  10.140845,  11.408451,  12.676056,  13.943662,  15.211267,
              16.478872,  17.746479,  19.014084,  20.28169 ,  21.549295,  22.816902,
              24.084507,  25.352112,  26.619719,  27.887323,  29.15493 ,  30.422535,
              31.690142,  32.957745,  34.225353,  35.492958,  36.760563,  38.028168,
              39.295776,  40.56338 ,  41.830986,  43.09859 ,  44.366196,  45.633804,
              46.90141 ,  48.169014,  49.43662 ,  50.704224,  51.971832,  53.239437,
              54.507042,  55.774647,  57.042255,  58.30986 ,  59.577465,  60.84507 ,
              62.112675,  63.380283,  64.64789 ,  65.91549 ,  67.1831  ,  68.45071 ,
              69.71831 ,  70.985916,  72.253525,  73.521126,  74.788734,  76.056335,
              77.323944,  78.59155 ,  79.85915 ,  81.12676 ,  82.39436 ,  83.66197 ,
              84.92958 ,  86.19718 ,  87.46479 ,  88.73239 ,  90.      ],
            dtype=float32)
    • lon
      (lon)
      float32
      0.0 2.5 5.0 ... 352.5 355.0 357.5
      axis :
      X
      standard_name :
      longitude
      long_name :
      Longitude
      units :
      degrees_east
      array([  0. ,   2.5,   5. ,   7.5,  10. ,  12.5,  15. ,  17.5,  20. ,  22.5,
              25. ,  27.5,  30. ,  32.5,  35. ,  37.5,  40. ,  42.5,  45. ,  47.5,
              50. ,  52.5,  55. ,  57.5,  60. ,  62.5,  65. ,  67.5,  70. ,  72.5,
              75. ,  77.5,  80. ,  82.5,  85. ,  87.5,  90. ,  92.5,  95. ,  97.5,
             100. , 102.5, 105. , 107.5, 110. , 112.5, 115. , 117.5, 120. , 122.5,
             125. , 127.5, 130. , 132.5, 135. , 137.5, 140. , 142.5, 145. , 147.5,
             150. , 152.5, 155. , 157.5, 160. , 162.5, 165. , 167.5, 170. , 172.5,
             175. , 177.5, 180. , 182.5, 185. , 187.5, 190. , 192.5, 195. , 197.5,
             200. , 202.5, 205. , 207.5, 210. , 212.5, 215. , 217.5, 220. , 222.5,
             225. , 227.5, 230. , 232.5, 235. , 237.5, 240. , 242.5, 245. , 247.5,
             250. , 252.5, 255. , 257.5, 260. , 262.5, 265. , 267.5, 270. , 272.5,
             275. , 277.5, 280. , 282.5, 285. , 287.5, 290. , 292.5, 295. , 297.5,
             300. , 302.5, 305. , 307.5, 310. , 312.5, 315. , 317.5, 320. , 322.5,
             325. , 327.5, 330. , 332.5, 335. , 337.5, 340. , 342.5, 345. , 347.5,
             350. , 352.5, 355. , 357.5], dtype=float32)
    • time
      (time)
      datetime64[ns]
      1850-01-16T12:00:00 ... 2014-12-...
      axis :
      T
      standard_name :
      time
      long_name :
      Time axis
      time_origin :
      1850-01-01 00:00:00
      bounds :
      time_bounds
      array(['1850-01-16T12:00:00.000000000', '1850-02-15T00:00:00.000000000',
             '1850-03-16T12:00:00.000000000', ..., '2014-10-16T12:00:00.000000000',
             '2014-11-16T00:00:00.000000000', '2014-12-16T12:00:00.000000000'],
            dtype='datetime64[ns]')
    • time_bounds
      (time, axis_nbounds)
      datetime64[ns]
      ...
      array([['1850-01-01T00:00:00.000000000', '1850-02-01T00:00:00.000000000'],
             ['1850-02-01T00:00:00.000000000', '1850-03-01T00:00:00.000000000'],
             ['1850-03-01T00:00:00.000000000', '1850-04-01T00:00:00.000000000'],
             ...,
             ['2014-10-01T00:00:00.000000000', '2014-11-01T00:00:00.000000000'],
             ['2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
             ['2014-12-01T00:00:00.000000000', '2015-01-01T00:00:00.000000000']],
            dtype='datetime64[ns]')
    • ts
      (time, lat, lon)
      float32
      ...
      long_name :
      Surface Temperature
      units :
      K
      online_operation :
      average
      cell_methods :
      area: time: mean
      interval_operation :
      900 s
      interval_write :
      1 month
      standard_name :
      surface_temperature
      description :
      Surface temperature (skin for open ocean)
      history :
      none
      cell_measures :
      area: areacella
      [40772160 values with dtype=float32]
  • Conventions :
    CF-1.7 CMIP-6.2
    creation_date :
    2018-07-11T07:36:33Z
    tracking_id :
    hdl:21.14100/3168f5b1-bf0a-4aec-931f-73c9d0034a45
    description :
    CMIP6 historical
    title :
    IPSL-CM6A-LR model output prepared for CMIP6 / CMIP historical
    activity_id :
    CMIP
    contact :
    ipsl-cmip6@listes.ipsl.fr
    data_specs_version :
    01.00.21
    dr2xml_version :
    1.11
    experiment_id :
    historical
    experiment :
    all-forcing simulation of the recent past
    external_variables :
    areacella
    forcing_index :
    1
    frequency :
    mon
    grid :
    LMDZ grid
    grid_label :
    gr
    nominal_resolution :
    250 km
    initialization_index :
    1
    institution_id :
    IPSL
    institution :
    Institut Pierre Simon Laplace, Paris 75252, France
    license :
    CMIP6 model data produced by IPSL is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (https://creativecommons.org/licenses). Consult https://pcmdi.llnl.gov/CMIP6/TermsOfUse for terms of use governing CMIP6 output, including citation requirements and proper acknowledgment. Further information about this data, including some limitations, can be found via the further_info_url (recorded as a global attribute in this file) and at https://cmc.ipsl.fr/. The data producers and data providers make no warranty, either express or implied, including, but not limited to, warranties of merchantability and fitness for a particular purpose. All liabilities arising from the supply of the information (including any liability arising in negligence) are excluded to the fullest extent permitted by law.
    mip_era :
    CMIP6
    parent_experiment_id :
    piControl
    parent_mip_era :
    CMIP6
    parent_activity_id :
    CMIP
    parent_source_id :
    IPSL-CM6A-LR
    parent_time_units :
    days since 1850-01-01 00:00:00
    branch_method :
    standard
    branch_time_in_parent :
    21914.0
    branch_time_in_child :
    0.0
    physics_index :
    1
    product :
    model-output
    realm :
    atmos
    source :
    IPSL-CM6A-LR (2017): atmos: LMDZ (NPv6, N96; 144 x 143 longitude/latitude; 79 levels; top level 40000 m) land: ORCHIDEE (v2.0, Water/Carbon/Energy mode) ocean: NEMO-OPA (eORCA1.3, tripolar primarily 1deg; 362 x 332 longitude/latitude; 75 levels; top grid cell 0-2 m) ocnBgchem: NEMO-PISCES seaIce: NEMO-LIM3
    source_id :
    IPSL-CM6A-LR
    source_type :
    AOGCM BGC
    sub_experiment_id :
    none
    sub_experiment :
    none
    table_id :
    Amon
    variable_id :
    ts
    EXPID :
    historical
    CMIP6_CV_version :
    cv=6.2.3.5-2-g63b123e
    dr2xml_md5sum :
    f1e40c1fc5d8281f865f72fbf4e38f9d
    model_version :
    6.1.5
    parent_variant_label :
    r1i1p1f1
    name :
    /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_%start_date%-%end_date%
    further_info_url :
    https://furtherinfo.es-doc.org/CMIP6.IPSL.IPSL-CM6A-LR.historical.none.r1i1p1f1
    variant_label :
    r1i1p1f1
    realization_index :
    1
    history :
    Sat Dec 1 12:17:27 2018: ncatted -O -a realization_index,global,m,i,1 /ccc/work/cont003/cmip6/cmip6/onhold/CM61-LR-histEXT-03.1910/files+ext/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc Sat Dec 1 12:11:36 2018: ncatted -O -a realization_index,global,m,i,1 /ccc/work/cont003/cmip6/cmip6/onhold/CM61-LR-hist-03.1910/files/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc Sat Dec 1 11:05:48 2018: ncatted -O -a realization_index,global,m,i,1 /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc Fri Nov 30 16:52:19 2018: ncatted -O -a realization_index,global,m,s,1 /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001-201412.nc Thu Nov 29 16:56:50 2018: ncatted -O -a variant_label,global,m,c,r1i1p1f1 /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r3i1p1f1_gr_185001-201412.nc Thu Nov 29 16:56:50 2018: ncatted -O -a further_info_url,global,m,c,https://furtherinfo.es-doc.org/CMIP6.IPSL.IPSL-CM6A-LR.historical.none.r1i1p1f1 /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r3i1p1f1_gr_185001-201412.nc Thu Nov 29 16:56:50 2018: ncatted -O -a name,global,m,c,/ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_%start_date%-%end_date% /ccc/work/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/CMIP6/ATM/ts_Amon_IPSL-CM6A-LR_historical_r3i1p1f1_gr_185001-201412.nc Mon Sep 3 14:53:28 2018: ncatted -O -a parent_variant_label,global,m,c,r1i1p1f1 ts_Amon_IPSL-CM6A-LR_historical_r3i1p1f1_gr_185001-201412.nc none
    NCO :
    "4.6.0"
In [8]:
d2
Out[8]:
<xarray.Dataset>
Dimensions:    (time: 1980, bnds: 2, lat: 128, lon: 256)
Coordinates:
  * time       (time) datetime64[ns] 1850-01-16T12:00:00 ... 2014-12-16T12:00:00
  * lat        (lat) float64 -88.93 -87.54 -86.14 -84.74 ... 86.14 87.54 88.93
  * lon        (lon) float64 0.0 1.406 2.812 4.219 ... 354.4 355.8 357.2 358.6
Dimensions without coordinates: bnds
Data variables:
    time_bnds  (time, bnds) datetime64[ns] 1850-01-01 1850-02-01 ... 2015-01-01
    lat_bnds   (lat, bnds) float64 -90.0 -88.28 -88.28 ... 88.28 88.28 90.0
    lon_bnds   (lon, bnds) float64 -0.7031 0.7031 0.7031 ... 357.9 357.9 359.3
    ts         (time, lat, lon) float32 ...
Attributes: (12/45)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   0.0
    branch_time_in_parent:  0.0
    creation_date:          2018-11-30T16:15:09Z
    ...                     ...
    variable_id:            ts
    variant_label:          r1i1p1f1
    license:                CMIP6 model data produced by MIROC is licensed un...
    cmor_version:           3.3.2
    tracking_id:            hdl:21.14100/24645cf7-2812-40bc-a320-cfc906678afe
    NCO:                    netCDF Operators version 4.7.6 (Homepage = http:/...
xarray.Dataset
    • time: 1980
    • bnds: 2
    • lat: 128
    • lon: 256
    • time
      (time)
      datetime64[ns]
      1850-01-16T12:00:00 ... 2014-12-...
      bounds :
      time_bnds
      axis :
      T
      long_name :
      time
      standard_name :
      time
      array(['1850-01-16T12:00:00.000000000', '1850-02-15T00:00:00.000000000',
             '1850-03-16T12:00:00.000000000', ..., '2014-10-16T12:00:00.000000000',
             '2014-11-16T00:00:00.000000000', '2014-12-16T12:00:00.000000000'],
            dtype='datetime64[ns]')
    • lat
      (lat)
      float64
      -88.93 -87.54 ... 87.54 88.93
      bounds :
      lat_bnds
      units :
      degrees_north
      axis :
      Y
      long_name :
      Latitude
      standard_name :
      latitude
      array([-88.927735, -87.538705, -86.141472, -84.742386, -83.342596, -81.942466,
             -80.542146, -79.14171 , -77.741196, -76.340629, -74.940023, -73.539389,
             -72.138732, -70.738059, -69.337372, -67.936673, -66.535966, -65.135251,
             -63.73453 , -62.333803, -60.933072, -59.532337, -58.131598, -56.730857,
             -55.330112, -53.929366, -52.528617, -51.127867, -49.727115, -48.326361,
             -46.925606, -45.52485 , -44.124093, -42.723335, -41.322576, -39.921816,
             -38.521056, -37.120294, -35.719532, -34.31877 , -32.918007, -31.517244,
             -30.11648 , -28.715716, -27.314951, -25.914186, -24.513421, -23.112655,
             -21.71189 , -20.311124, -18.910357, -17.509591, -16.108824, -14.708057,
             -13.30729 , -11.906523, -10.505756,  -9.104989,  -7.704221,  -6.303454,
              -4.902687,  -3.501919,  -2.101151,  -0.700384,   0.700384,   2.101151,
               3.501919,   4.902687,   6.303454,   7.704221,   9.104989,  10.505756,
              11.906523,  13.30729 ,  14.708057,  16.108824,  17.509591,  18.910357,
              20.311124,  21.71189 ,  23.112655,  24.513421,  25.914186,  27.314951,
              28.715716,  30.11648 ,  31.517244,  32.918007,  34.31877 ,  35.719532,
              37.120294,  38.521056,  39.921816,  41.322576,  42.723335,  44.124093,
              45.52485 ,  46.925606,  48.326361,  49.727115,  51.127867,  52.528617,
              53.929366,  55.330112,  56.730857,  58.131598,  59.532337,  60.933072,
              62.333803,  63.73453 ,  65.135251,  66.535966,  67.936673,  69.337372,
              70.738059,  72.138732,  73.539389,  74.940023,  76.340629,  77.741196,
              79.14171 ,  80.542146,  81.942466,  83.342596,  84.742386,  86.141472,
              87.538705,  88.927735])
    • lon
      (lon)
      float64
      0.0 1.406 2.812 ... 357.2 358.6
      bounds :
      lon_bnds
      units :
      degrees_east
      axis :
      X
      long_name :
      Longitude
      standard_name :
      longitude
      array([  0.     ,   1.40625,   2.8125 , ..., 355.78125, 357.1875 , 358.59375])
    • time_bnds
      (time, bnds)
      datetime64[ns]
      ...
      array([['1850-01-01T00:00:00.000000000', '1850-02-01T00:00:00.000000000'],
             ['1850-02-01T00:00:00.000000000', '1850-03-01T00:00:00.000000000'],
             ['1850-03-01T00:00:00.000000000', '1850-04-01T00:00:00.000000000'],
             ...,
             ['2014-10-01T00:00:00.000000000', '2014-11-01T00:00:00.000000000'],
             ['2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
             ['2014-12-01T00:00:00.000000000', '2015-01-01T00:00:00.000000000']],
            dtype='datetime64[ns]')
    • lat_bnds
      (lat, bnds)
      float64
      ...
      array([[-90.      , -88.282245],
             [-88.282245, -86.866422],
             [-86.866422, -85.459991],
             ...,
             [ 85.459991,  86.866422],
             [ 86.866422,  88.282245],
             [ 88.282245,  90.      ]])
    • lon_bnds
      (lon, bnds)
      float64
      ...
      array([[ -0.703125,   0.703125],
             [  0.703125,   2.109375],
             [  2.109375,   3.515625],
             ...,
             [355.078125, 356.484375],
             [356.484375, 357.890625],
             [357.890625, 359.296875]])
    • ts
      (time, lat, lon)
      float32
      ...
      standard_name :
      surface_temperature
      long_name :
      Surface Temperature
      comment :
      Temperature of the lower boundary of the atmosphere
      units :
      K
      original_name :
      GRTS
      cell_methods :
      area: time: mean
      cell_measures :
      area: areacella
      history :
      2018-11-30T16:15:08Z altered by CMOR: replaced missing value flag (-999) with standard missing value (1e+20). 2018-11-30T16:15:09Z altered by CMOR: Inverted axis: lat.
      [64880640 values with dtype=float32]
  • Conventions :
    CF-1.7 CMIP-6.2
    activity_id :
    CMIP
    branch_method :
    standard
    branch_time_in_child :
    0.0
    branch_time_in_parent :
    0.0
    creation_date :
    2018-11-30T16:15:09Z
    data_specs_version :
    01.00.28
    experiment :
    all-forcing simulation of the recent past
    experiment_id :
    historical
    external_variables :
    areacella
    forcing_index :
    1
    frequency :
    mon
    further_info_url :
    https://furtherinfo.es-doc.org/CMIP6.MIROC.MIROC6.historical.none.r1i1p1f1
    grid :
    native atmosphere T85 Gaussian grid
    grid_label :
    gn
    history :
    Thu Mar 21 11:28:13 2019: ncrcat ts_Amon_MIROC6_historical_r1i1p1f1_gn_185001-194912.nc ts_Amon_MIROC6_historical_r1i1p1f1_gn_195001-201412.nc ts_Amon_MIROC6_historical_r1i1p1f1_gn_185001-201412.nc 2018-11-30T16:15:09Z ; CMOR rewrote data to be consistent with CMIP6, CF-1.7 CMIP-6.2 and CF standards.
    initialization_index :
    1
    institution :
    JAMSTEC (Japan Agency for Marine-Earth Science and Technology, Kanagawa 236-0001, Japan), AORI (Atmosphere and Ocean Research Institute, The University of Tokyo, Chiba 277-8564, Japan), NIES (National Institute for Environmental Studies, Ibaraki 305-8506, Japan), and R-CCS (RIKEN Center for Computational Science, Hyogo 650-0047, Japan)
    institution_id :
    MIROC
    mip_era :
    CMIP6
    nominal_resolution :
    250 km
    parent_activity_id :
    CMIP
    parent_experiment_id :
    piControl
    parent_mip_era :
    CMIP6
    parent_source_id :
    MIROC6
    parent_time_units :
    days since 3200-1-1
    parent_variant_label :
    r1i1p1f1
    physics_index :
    1
    product :
    model-output
    realization_index :
    1
    realm :
    atmos
    source :
    MIROC6 (2017): aerosol: SPRINTARS6.0 atmos: CCSR AGCM (T85; 256 x 128 longitude/latitude; 81 levels; top level 0.004 hPa) atmosChem: none land: MATSIRO6.0 landIce: none ocean: COCO4.9 (tripolar primarily 1deg; 360 x 256 longitude/latitude; 63 levels; top grid cell 0-2 m) ocnBgchem: none seaIce: COCO4.9
    source_id :
    MIROC6
    source_type :
    AOGCM AER
    sub_experiment :
    none
    sub_experiment_id :
    none
    table_id :
    Amon
    table_info :
    Creation Date:(06 November 2018) MD5:0728c79344e0f262bb76e4f9ff0d9afc
    title :
    MIROC6 output prepared for CMIP6
    variable_id :
    ts
    variant_label :
    r1i1p1f1
    license :
    CMIP6 model data produced by MIROC is licensed under a Creative Commons Attribution ShareAlike 4.0 International License (https://creativecommons.org/licenses/). Consult https://pcmdi.llnl.gov/CMIP6/TermsOfUse for terms of use governing CMIP6 output, including citation requirements and proper acknowledgment. Further information about this data, including some limitations, can be found via the further_info_url (recorded as a global attribute in this file). The data producers and data providers make no warranty, either express or implied, including, but not limited to, warranties of merchantability and fitness for a particular purpose. All liabilities arising from the supply of the information (including any liability arising in negligence) are excluded to the fullest extent permitted by law.
    cmor_version :
    3.3.2
    tracking_id :
    hdl:21.14100/24645cf7-2812-40bc-a320-cfc906678afe
    NCO :
    netCDF Operators version 4.7.6 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)
In [9]:
d3
Out[9]:
<xarray.Dataset>
Dimensions:    (time: 1980, bnds: 2, lat: 160, lon: 320)
Coordinates:
  * time       (time) datetime64[ns] 1850-01-16T12:00:00 ... 2014-12-16T12:00:00
  * lat        (lat) float64 -89.14 -88.03 -86.91 -85.79 ... 86.91 88.03 89.14
  * lon        (lon) float64 0.0 1.125 2.25 3.375 ... 355.5 356.6 357.8 358.9
Dimensions without coordinates: bnds
Data variables:
    time_bnds  (time, bnds) datetime64[ns] 1850-01-01 1850-02-01 ... 2015-01-01
    lat_bnds   (lat, bnds) float64 -90.0 -88.59 -88.59 ... 88.59 88.59 90.0
    lon_bnds   (lon, bnds) float64 -0.5625 0.5625 0.5625 ... 358.3 358.3 359.4
    ts         (time, lat, lon) float32 ...
Attributes: (12/44)
    Conventions:            CF-1.7 CMIP-6.2
    activity_id:            CMIP
    branch_method:          standard
    branch_time_in_child:   0.0
    branch_time_in_parent:  0.0
    creation_date:          2019-02-20T02:26:52Z
    ...                     ...
    title:                  MRI-ESM2-0 output prepared for CMIP6
    variable_id:            ts
    variant_label:          r1i1p1f1
    license:                CMIP6 model data produced by MRI is licensed unde...
    cmor_version:           3.4.0
    tracking_id:            hdl:21.14100/83b81c22-3ba4-45c0-9e9b-3f94038f7cb7
xarray.Dataset
    • time: 1980
    • bnds: 2
    • lat: 160
    • lon: 320
    • time
      (time)
      datetime64[ns]
      1850-01-16T12:00:00 ... 2014-12-...
      bounds :
      time_bnds
      axis :
      T
      long_name :
      time
      standard_name :
      time
      array(['1850-01-16T12:00:00.000000000', '1850-02-15T00:00:00.000000000',
             '1850-03-16T12:00:00.000000000', ..., '2014-10-16T12:00:00.000000000',
             '2014-11-16T00:00:00.000000000', '2014-12-16T12:00:00.000000000'],
            dtype='datetime64[ns]')
    • lat
      (lat)
      float64
      -89.14 -88.03 ... 88.03 89.14
      bounds :
      lat_bnds
      units :
      degrees_north
      axis :
      Y
      long_name :
      Latitude
      standard_name :
      latitude
      array([-89.14152, -88.02943, -86.91077, -85.79063, -84.66992, -83.54895,
             -82.42782, -81.30659, -80.18531, -79.06398, -77.94262, -76.82124,
             -75.69984, -74.57843, -73.45701, -72.33558, -71.21414, -70.09269,
             -68.97124, -67.84978, -66.72833, -65.60686, -64.4854 , -63.36393,
             -62.24246, -61.12099, -59.99952, -58.87804, -57.75657, -56.63509,
             -55.51361, -54.39214, -53.27066, -52.14917, -51.02769, -49.90621,
             -48.78473, -47.66325, -46.54176, -45.42028, -44.29879, -43.17731,
             -42.05582, -40.93434, -39.81285, -38.69137, -37.56988, -36.44839,
             -35.32691, -34.20542, -33.08393, -31.96244, -30.84096, -29.71947,
             -28.59798, -27.47649, -26.355  , -25.23351, -24.11203, -22.99054,
             -21.86905, -20.74756, -19.62607, -18.50458, -17.38309, -16.2616 ,
             -15.14011, -14.01862, -12.89713, -11.77564, -10.65415,  -9.53266,
              -8.41117,  -7.28968,  -6.16819,  -5.0467 ,  -3.92521,  -2.80372,
              -1.68223,  -0.56074,   0.56074,   1.68223,   2.80372,   3.92521,
               5.0467 ,   6.16819,   7.28968,   8.41117,   9.53266,  10.65415,
              11.77564,  12.89713,  14.01862,  15.14011,  16.2616 ,  17.38309,
              18.50458,  19.62607,  20.74756,  21.86905,  22.99054,  24.11203,
              25.23351,  26.355  ,  27.47649,  28.59798,  29.71947,  30.84096,
              31.96244,  33.08393,  34.20542,  35.32691,  36.44839,  37.56988,
              38.69137,  39.81285,  40.93434,  42.05582,  43.17731,  44.29879,
              45.42028,  46.54176,  47.66325,  48.78473,  49.90621,  51.02769,
              52.14917,  53.27066,  54.39214,  55.51361,  56.63509,  57.75657,
              58.87804,  59.99952,  61.12099,  62.24246,  63.36393,  64.4854 ,
              65.60686,  66.72833,  67.84978,  68.97124,  70.09269,  71.21414,
              72.33558,  73.45701,  74.57843,  75.69984,  76.82124,  77.94262,
              79.06398,  80.18531,  81.30659,  82.42782,  83.54895,  84.66992,
              85.79063,  86.91077,  88.02943,  89.14152])
    • lon
      (lon)
      float64
      0.0 1.125 2.25 ... 357.8 358.9
      bounds :
      lon_bnds
      units :
      degrees_east
      axis :
      X
      long_name :
      Longitude
      standard_name :
      longitude
      array([  0.   ,   1.125,   2.25 , ..., 356.625, 357.75 , 358.875])
    • time_bnds
      (time, bnds)
      datetime64[ns]
      ...
      array([['1850-01-01T00:00:00.000000000', '1850-02-01T00:00:00.000000000'],
             ['1850-02-01T00:00:00.000000000', '1850-03-01T00:00:00.000000000'],
             ['1850-03-01T00:00:00.000000000', '1850-04-01T00:00:00.000000000'],
             ...,
             ['2014-10-01T00:00:00.000000000', '2014-11-01T00:00:00.000000000'],
             ['2014-11-01T00:00:00.000000000', '2014-12-01T00:00:00.000000000'],
             ['2014-12-01T00:00:00.000000000', '2015-01-01T00:00:00.000000000']],
            dtype='datetime64[ns]')
    • lat_bnds
      (lat, bnds)
      float64
      ...
      array([[-90.      , -88.585475],
             [-88.585475, -87.4701  ],
             [-87.4701  , -86.3507  ],
             ...,
             [ 86.3507  ,  87.4701  ],
             [ 87.4701  ,  88.585475],
             [ 88.585475,  90.      ]])
    • lon_bnds
      (lon, bnds)
      float64
      ...
      array([[ -0.5625,   0.5625],
             [  0.5625,   1.6875],
             [  1.6875,   2.8125],
             ...,
             [356.0625, 357.1875],
             [357.1875, 358.3125],
             [358.3125, 359.4375]])
    • ts
      (time, lat, lon)
      float32
      ...
      standard_name :
      surface_temperature
      long_name :
      Surface Temperature
      comment :
      Temperature of the lower boundary of the atmosphere
      units :
      K
      original_name :
      TGEF
      cell_methods :
      area: time: mean
      cell_measures :
      area: areacella
      history :
      2019-02-20T02:26:51Z altered by CMOR: replaced missing value flag (-9.99e+33) with standard missing value (1e+20).
      [101376000 values with dtype=float32]
  • Conventions :
    CF-1.7 CMIP-6.2
    activity_id :
    CMIP
    branch_method :
    standard
    branch_time_in_child :
    0.0
    branch_time_in_parent :
    0.0
    creation_date :
    2019-02-20T02:26:52Z
    data_specs_version :
    01.00.29
    experiment :
    all-forcing simulation of the recent past
    experiment_id :
    historical
    external_variables :
    areacella
    forcing_index :
    1
    frequency :
    mon
    further_info_url :
    https://furtherinfo.es-doc.org/CMIP6.MRI.MRI-ESM2-0.historical.none.r1i1p1f1
    grid :
    native atmosphere TL159 gaussian grid (160x320 latxlon)
    grid_label :
    gn
    history :
    2019-02-20T02:26:52Z ; CMOR rewrote data to be consistent with CMIP6, CF-1.7 CMIP-6.2 and CF standards.; Output from run-Dr060_historical_101 (sfc_avr_mon.ctl)
    initialization_index :
    1
    institution :
    Meteorological Research Institute, Tsukuba, Ibaraki 305-0052, Japan
    institution_id :
    MRI
    mip_era :
    CMIP6
    nominal_resolution :
    100 km
    parent_activity_id :
    CMIP
    parent_experiment_id :
    piControl
    parent_mip_era :
    CMIP6
    parent_source_id :
    MRI-ESM2-0
    parent_time_units :
    days since 1850-01-01
    parent_variant_label :
    r1i1p1f1
    physics_index :
    1
    product :
    model-output
    realization_index :
    1
    realm :
    atmos
    source :
    MRI-ESM2.0 (2017): aerosol: MASINGAR mk2r4 (TL95; 192 x 96 longitude/latitude; 80 levels; top level 0.01 hPa) atmos: MRI-AGCM3.5 (TL159; 320 x 160 longitude/latitude; 80 levels; top level 0.01 hPa) atmosChem: MRI-CCM2.1 (T42; 128 x 64 longitude/latitude; 80 levels; top level 0.01 hPa) land: HAL 1.0 landIce: none ocean: MRI.COM4.4 (tripolar primarily 0.5 deg latitude/1 deg longitude with meridional refinement down to 0.3 deg within 10 degrees north and south of the equator; 360 x 364 longitude/latitude; 61 levels; top grid cell 0-2 m) ocnBgchem: MRI.COM4.4 seaIce: MRI.COM4.4
    source_id :
    MRI-ESM2-0
    source_type :
    AOGCM AER CHEM
    sub_experiment :
    none
    sub_experiment_id :
    none
    table_id :
    Amon
    table_info :
    Creation Date:(14 December 2018) MD5:b2d32d1a0d9b196411429c8895329d8f
    title :
    MRI-ESM2-0 output prepared for CMIP6
    variable_id :
    ts
    variant_label :
    r1i1p1f1
    license :
    CMIP6 model data produced by MRI is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License (https://creativecommons.org/licenses/). Consult https://pcmdi.llnl.gov/CMIP6/TermsOfUse for terms of use governing CMIP6 output, including citation requirements and proper acknowledgment. Further information about this data, including some limitations, can be found via the further_info_url (recorded as a global attribute in this file). The data producers and data providers make no warranty, either express or implied, including, but not limited to, warranties of merchantability and fitness for a particular purpose. All liabilities arising from the supply of the information (including any liability arising in negligence) are excluded to the fullest extent permitted by law.
    cmor_version :
    3.4.0
    tracking_id :
    hdl:21.14100/83b81c22-3ba4-45c0-9e9b-3f94038f7cb7
In [23]:
#let's visualize some models, visualizzazione dell'anno 2014
p0 = d1.ts.isel(time=-1).plot(transform=ccrs.PlateCarree(),subplot_kws={'projection': ccrs.Robinson()},
                            cmap='jet')
p0.axes.coastlines()
Out[23]:
<cartopy.mpl.feature_artist.FeatureArtist at 0x2b39b6dbdf0>
In [24]:
p1=d2.ts.isel(time=-1).plot(transform=ccrs.PlateCarree(),subplot_kws={'projection': ccrs.Robinson()},
                            cmap='jet')
p1.axes.coastlines()
Out[24]:
<cartopy.mpl.feature_artist.FeatureArtist at 0x2b39b923340>
In [25]:
p2=d3.ts.isel(time=-1).plot(transform=ccrs.PlateCarree(),subplot_kws={'projection': ccrs.Robinson()},
                            cmap='jet')
p2.axes.coastlines()
Out[25]:
<cartopy.mpl.feature_artist.FeatureArtist at 0x2b39b7e1ff0>
In [10]:
#calculate normals
n1=d1.ts.sel(time=slice("1961-01-16T12:00:00.000000000","1990-12-16T12:00:00.000000000")
            ).groupby("time.month").mean()
n2=d2.ts.sel(time=slice("1961-01-16T12:00:00.000000000","1990-12-16T12:00:00.000000000")
            ).groupby("time.month").mean()
n3=d3.ts.sel(time=slice("1961-01-16T12:00:00.000000000","1990-12-16T12:00:00.000000000")
            ).groupby("time.month").mean()
In [11]:
# Second,calculate temperature anomalies

anom1 = d1.ts.groupby("time.month")-n1 
anom2 = d2.ts.groupby("time.month")-n2
anom3 = d3.ts.groupby("time.month")-n3
In [12]:
# Weights

weights1 = np.cos(np.deg2rad(d1.lat))
weights2 = np.cos(np.deg2rad(d2.lat))
weights3 = np.cos(np.deg2rad(d3.lat))
In [13]:
#Aggregation
enst = xr.Dataset()
enst['ts1'] = anom1.weighted(weights1).mean(("lon", "lat"),keep_attrs=True).resample(time="Y").mean()
enst['ts2'] = anom2.weighted(weights2).mean(("lon", "lat")).resample(time="Y").mean()
enst['ts3'] = anom3.weighted(weights3).mean(("lon", "lat")).resample(time="Y").mean()

Let's make a comparison between the real situation and the situation predicted from the model

In [14]:
plt.plot(enst.ts1)
plt.plot(enst.ts2)
plt.plot(enst.ts3)
Out[14]:
[<matplotlib.lines.Line2D at 0x2b395ba4d60>]
In [15]:
# Fourth, we can calculate the ensemble mean time series of global mean temperature anomalies

# Calculate the standard deviation of the 3 models

ens_mean = enst.to_array(dim='new').mean('new')
ens_std = enst.to_array(dim='new2').std('new2')

enst['ens_mean'] = ens_mean 
enst['ens_std'] = ens_std
In [31]:
data=global_temp.groupby('years').agg({'LandAverageTemperature':'mean','LandAverageTemperatureUncertainty':'mean'}).reset_index()
obs=data[data['years']>='1850']
obs=obs[obs['years']<'2015']
ref=obs[obs['years']>='1961']
ref=ref[ref['years']<='1990']

Let's calculate anomalies for the temperatures, from our dataset global_temp_country and confront them with the anomalies of the model ensemble

In [32]:
media=ref.mean()['LandAverageTemperature']
In [33]:
#CALCOLO ANOMALIE
obs['temp2']=obs['LandAverageTemperature']-media
In [34]:
t=enst.ens_mean
p=enst.time
t=pd.DataFrame(t,p)
t=t.reset_index()
t['data']=pd.to_datetime(t['index'],format='%Y%m%d')
t['year']=pd.DatetimeIndex(t['data']).year
t.rename(columns={0:'temp'},inplace=True)
In [35]:
t
Out[35]:
index temp data year
0 1850-12-31 -0.259619 1850-12-31 1850
1 1851-12-31 -0.216288 1851-12-31 1851
2 1852-12-31 -0.240269 1852-12-31 1852
3 1853-12-31 -0.242512 1853-12-31 1853
4 1854-12-31 -0.147570 1854-12-31 1854
... ... ... ... ...
160 2010-12-31 0.526859 2010-12-31 2010
161 2011-12-31 0.410785 2011-12-31 2011
162 2012-12-31 0.547878 2012-12-31 2012
163 2013-12-31 0.628964 2013-12-31 2013
164 2014-12-31 0.558643 2014-12-31 2014

165 rows × 4 columns

In [36]:
obs=obs.reset_index()
In [37]:
t['temp2']=obs['temp2']
In [38]:
t.rename(columns={'temp2':'reality','temp':'simulated'},inplace=True)

fig=px.line(t,x='year',y=['simulated','reality'],title='Anomalies in Temperature in reality vs simulated')
fig.show()

From this graphic we can see that the Global Land Temperature is increased more than the models have predicted, it seems interesting to confront the growing trend from the 1950. In this year, from the graphic of CO2 in the course of years that we have shown before, we can see that there has been an increase of CO2 that coincides with the growth of trend in this graphic. Our ensemble of models has predcited quite well the average temperature